
layui.define(["jquery"], function (exports) {
    var $ = layui.jquery,
        storage = window.sessionStorage,loginSta = '',
        sellerIdLogin = storage.getItem("sellerId"),
        sellerNameLogin = storage.getItem("sellerName"),
        serverIdLogin = storage.getItem("serviceId"),
        serverNameLogin = storage.getItem("serviceName"),
        loginUrl = '/page/login.html',
        //loginUrl = '/flexible_merchant/page/login.html',
        curHref = window.location.href, API = layui.tfApi;

    $.post("http://183.129.193.42:13391/server/user/isLogin",function (res) {
        var _ls = JSON.parse(res);
        console.log(_ls);
        console.log(curHref.indexOf("login"));
        if(_ls.code == "-1" && (curHref.indexOf("login") < 0)){
            window.location = loginUrl;
            return false;

        }
    });


    var tfApi = {
        CURL1: "http://183.129.193.42:13391",
        CURL: "http://183.129.193.42:13391/server",
        login:{
            sellerLogin : "/user/login" // 商户登录,
            ,serverLogin : "/user/serviceLogin"  // 服务商登录
            ,isLogin : '/user/isLogin'  // 检测是否登录；
        },
        postAjax: function(_url,data,callback){ // ajax class;
            $.ajax({
                url:this.CURL + _url,
                type: 'POST',
                async:true,
                dataType:'JSON',
                xhrFields:{
                    withCredentials:true
                },
                crossDomain: true,
                headers:{'Content-Type':'application/json;charset=utf8'},
                data: JSON.stringify(data), // 对象转字符串
                success:callback //成功回调函数
            });
        },
        numFun : function _formatAmount(strData) {
            var CurrencyAndAmountRegExp = /^(\d{1,18})|(\d{1,18}\.)|(\d{1,17}\.\d{0,1})|(\d{1,16}\.\d{0,2})|(\.\d{1,2})$/;
            var _result = CurrencyAndAmountRegExp.test(strData);
            if(_result == false){
                return strData;
            }

            var n = 2; // n = n > 0 && n <= 6 ? n : 2;// 小数点位数；
            var formatData = parseFloat((strData + '').replace(/[^\d\.-]/g, '')).toFixed(n) + '';
            var l = formatData.split('.')[0].split('').reverse();
            var r = formatData.split('.')[1];
            var t = '';
            for(i = 0; i < l.length; i ++ ) {
                t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? ',' : '');
            }
            var str=t.split('').reverse().join('') + '.' + r;
            str=str.replace("-,",'-');
            return str;
        },
        invoice:{
            // qryInvoice: "/seller/qryNeedBill", // 充值凭证查询-申请发票-列表
            qryInvoice: "/seller/qryCanprovide", // 充值凭证查询-申请发票-列表
            qryConsignee: "/invoice/qryConsignee", // 查询收件人
            qryTaxType: "/invoice/qryTaxType", // 查询开票内容
            qryInvoiceInfo: "/invoice/qryInvoiceInfo", // 查询购买方和开票方信息
            insSellerBill: "/invoice/insSellerBill", // 发票新增
            qryBills: "/invoice/qryBills", // 发票查询
            qryConsigneeList: "/invoice/qryConsigneeList", // 收件人查询
            insConsignee: "/invoice/insConsignee", // 收件人新增
            updConsignee: "/invoice/updConsignee", // 收件人修改
            delConsignee: "/invoice/delConsignee", // 收件人删除
        }
    };
    exports("tfApi", tfApi);
});
